package com.share.finance.risk.third.service.http.tyc;

import com.alibaba.fastjson.JSON;
import com.share.common.utils.HttpUtil;
import com.share.finance.risk.common.model.sys.ThirdRequest;
import com.share.finance.risk.third.model.db.InterfaceConfig;
import com.share.finance.risk.third.service.IInterfaceConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class TycHttpService {
    @Autowired
    private IInterfaceConfigService interfaceConfigService;

    public String http(ThirdRequest thirdRequest, Map<String, Object> param) {
        InterfaceConfig config = interfaceConfigService.getInterfaceConfig(thirdRequest.getIntId());
        String result = null;
        String url = config.getIntUrl();
        String jsonStr = JSON.toJSONString(param);
        try {
            result = HttpUtil.post(url, jsonStr);
        } catch (Exception e) {
            log.error("请求异常url={}", url, e);
        }
        //这里使用了应用类型,内部向上传递
        thirdRequest.setHttpParam(jsonStr);
        return result;
    }
}
